/**
    入驻小区
**/
(function (vc) {
    let DEFAULT_PAGE = 1;
    let DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            partnerOrdersInfo: {
                partnerOrderss: [],
                partners:[],
                total: 0,
                records: 1,
                moreCondition: false,
                pgId: '',
                conditions: {
                    ppId: '',
                    orderId: '',
                    personName: '',
                    personTel: '',
                    state: '',

                }
            }
        },
        _initMethod: function () {
            $that._listPartners();
           
        },
        _initEvent: function () {
            vc.on('partnerOrders', 'listPartnerOrders', function (_param) {
                $that._listPartnerOrderss(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listPartnerOrderss(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listPartnerOrderss: function (_page, _rows) {
                $that.partnerOrdersInfo.conditions.page = _page;
                $that.partnerOrdersInfo.conditions.row = _rows;
                $that.partnerOrdersInfo.conditions.shopId = vc.getCurrentCommunity().shopId;
                let param = {
                    params: $that.partnerOrdersInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/partner.listPartnerOrder',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.partnerOrdersInfo.total = _json.total;
                        $that.partnerOrdersInfo.records = _json.records;
                        $that.partnerOrdersInfo.partnerOrderss = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.partnerOrdersInfo.records,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            
            _queryPartnerOrdersMethod: function () {
                $that._listPartnerOrderss(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.partnerOrdersInfo.moreCondition) {
                    $that.partnerOrdersInfo.moreCondition = false;
                } else {
                    $that.partnerOrdersInfo.moreCondition = true;
                }
            },
            _toOrderDetail:function(_order){
                vc.jumpToPage('/#/pages/goods/storeOrderCartDetail?orderId=' + _order.orderId);
            },
            _listPartners: function (_page, _rows) {

                let param = {
                    params: {
                        page:1,
                        row:100,
                        shopId:vc.getCurrentCommunity().shopId
                    }
                };

                //发送get请求
                vc.http.apiGet('/partner.listPartnerPool',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.partnerOrdersInfo.partners = _json.data;
                        if(_json.data && _json.data.length >0){
                            $that.partnerOrdersInfo.conditions.ppId = _json.data[0].ppId;
                            $that._listPartnerOrderss(DEFAULT_PAGE, DEFAULT_ROWS);
                        }
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
        }
    });
})(window.vc);
